<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小说目录</title>
    <style>
        /* 明亮模式 */
        :root {
            --body-font-size: 16px;
            --content-font-size: 16px;
        }

        body {
            font-family: 'SimSun', '宋体', serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            background-color: #f8f8f8;
            color: #333;
            font-size: var(--body-font-size);
        }

        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: #fff;
            padding: 40px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 40px;
        }

        .last-read {
            background-color: #e3f2fd;
            padding: 15px;
            border-radius: 5px;
            margin-bottom: 30px;
            border-left: 4px solid #2196f3;
        }

        .last-read-title {
            font-weight: bold;
            margin-bottom: 10px;
            color: #1565c0;
        }

        .last-read a {
            color: #1976d2;
            text-decoration: none;
        }

        .last-read a:hover {
            text-decoration: underline;
        }

        .chapter-list {
            list-style-type: none;
            padding: 0;
        }

        .chapter-list li {
            margin-bottom: 10px;
        }

        .chapter-list a {
            color: #333;
            text-decoration: none;
            display: block;
            padding: 10px;
            border-radius: 4px;
            transition: all 0.3s;
        }

        .chapter-list a:hover {
            background-color: #f0f0f0;
            color: #0066cc;
        }

        .chapter-number {
            display: inline-block;
            width: 60px;
            text-align: right;
            margin-right: 15px;
            font-weight: bold;
        }

        /* 暗黑模式 */
        .dark-mode {
            --bg-color: #121212;
            --text-color: #e0e0e0;
            --container-bg: #1e1e1e;
            --border-color: #333;
            --link-color: #90caf9;
            --hover-color: #64b5f6;
        }

        .dark-mode body {
            background-color: var(--bg-color);
            color: var(--text-color);
        }

        .dark-mode .container {
            background-color: var(--container-bg);
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
        }

        .dark-mode h1 {
            color: var(--text-color);
        }

        .dark-mode .last-read {
            background-color: #1a237e;
            border-left-color: #5c6bc0;
        }

        .dark-mode .last-read-title {
            color: #9fa8da;
        }

        .dark-mode .last-read a {
            color: #bbdefb;
        }

        .dark-mode .chapter-list a {
            color: var(--text-color);
        }

        .dark-mode .chapter-list a:hover {
            background-color: #2d2d2d;
            color: var(--link-color);
        }

        /* 系统暗黑模式自动应用 */
        @media (prefers-color-scheme: dark) {
            body:not(.light-mode) {
                --bg-color: #121212;
                --text-color: #e0e0e0;
                --container-bg: #1e1e1e;
                --border-color: #333;
                --link-color: #90caf9;
                --hover-color: #64b5f6;
                background-color: var(--bg-color);
                color: var(--text-color);
            }

            body:not(.light-mode) .container {
                background-color: var(--container-bg);
                box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
            }

            body:not(.light-mode) h1 {
                color: var(--text-color);
            }

            body:not(.light-mode) .last-read {
                background-color: #1a237e;
                border-left-color: #5c6bc0;
            }

            body:not(.light-mode) .last-read-title {
                color: #9fa8da;
            }

            body:not(.light-mode) .last-read a {
                color: #bbdefb;
            }

            body:not(.light-mode) .chapter-list a {
                color: var(--text-color);
            }

            body:not(.light-mode) .chapter-list a:hover {
                background-color: #2d2d2d;
                color: var(--link-color);
            }
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>小说目录</h1>

        <!-- 上次阅读章节区域 -->
        <div id="last-read-section" class="last-read">
            <div class="last-read-title">上次阅读</div>
            <div id="last-read-content">正在加载...</div>
        </div>

        <ul class="chapter-list">
            $chapter_list
        </ul>
    </div>

    <script>
        // 初始化暗黑模式设置
        function initDarkMode() {
            const darkMode = localStorage.getItem('darkMode');
            const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;

            if (darkMode === 'true' || (darkMode === null && prefersDark)) {
                document.documentElement.classList.add('dark-mode');
            } else if (darkMode === 'false') {
                document.documentElement.classList.add('light-mode');
            }
        }

        // 显示上次阅读的章节
        function showLastReadChapter() {
            const lastReadChapter = localStorage.getItem('lastReadChapter');
            const lastReadContent = document.getElementById('last-read-content');

            if (lastReadChapter) {
                // 解析章节号
                const match = lastReadChapter.match(/chapters\/(\d+)\.html/);
                if (match && match[1]) {
                    const chapterNum = parseInt(match[1]);
                    // 查找对应的章节元素
                    const chapterElements = document.querySelectorAll('.chapter-list a');
                    let chapterTitle = '';

                    if (chapterElements.length >= chapterNum) {
                        const chapterElement = chapterElements[chapterNum - 1];
                        chapterTitle = chapterElement.textContent.replace(/^\d+\.\s*/, '');
                    }

                    lastReadContent.innerHTML = '继续阅读: <a href="' + lastReadChapter + '">' + chapterNum + '. ' + chapterTitle + '</a>';
                } else {
                    lastReadContent.textContent = '暂无阅读记录';
                }
            } else {
                lastReadContent.textContent = '暂无阅读记录';
            }
        }

        // 初始化
        initDarkMode();
        showLastReadChapter();
    </script>
</body>

</html>